﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CommodityShip : CommodityBase
{
    public Text m_NameT;
    public Text m_PriceT;
    public Image m_Perview;

    public Image m_LevelTagD;
    public Image m_LevelTagC;
    public Image m_LevelTagB;
    public Image m_LevelTagA;
    public Image m_LevelTagAP;
    public Ship Ship {
        set {
            if (null == value)
                return;
            m_CommodityShip = value;

            m_NameT.text = m_CommodityShip.m_ShipStruct.m_Name;
            m_PriceT.text = m_CommodityShip.m_ShipStruct.m_Price.ToString();
            m_Perview.sprite = m_CommodityShip.GetComponent<SpriteRenderer>().sprite;
            m_Perview.preserveAspect = true;

            m_LevelTagD.gameObject.SetActive(false);
            m_LevelTagC.gameObject.SetActive(false);
            m_LevelTagB.gameObject.SetActive(false);
            m_LevelTagA.gameObject.SetActive(false);
            m_LevelTagAP.gameObject.SetActive(false);

            switch(m_CommodityShip.m_ShipStruct.m_LicenseLevel)
            {
                case Driver.DriveLevel.LEVEL_D:
                    m_LevelTagD.gameObject.SetActive(true);
                    break;
                case Driver.DriveLevel.LEVEL_C:
                    m_LevelTagC.gameObject.SetActive(true);
                    break;
                case Driver.DriveLevel.LEVEL_B:
                    m_LevelTagB.gameObject.SetActive(true);
                    break;
                case Driver.DriveLevel.LEVEL_A:
                    m_LevelTagA.gameObject.SetActive(true);
                    break;
                case Driver.DriveLevel.LEVEL_AP:
                    m_LevelTagAP.gameObject.SetActive(true);
                    break;
            }
        }
        get { return m_CommodityShip; }
    }
    Ship m_CommodityShip;
    public override void onBuyClicked()
    {
        if (Player.Instance.Money < Ship.m_ShipStruct.m_Price)
        {
            MessageShow.Instance.Messaage("你钱不够");
            return;
        }
        Player.Instance.Money -= Ship.m_ShipStruct.m_Price;
        Player.Instance.addShip(m_CommodityShip);
        MessageShow.Instance.Messaage("已将\""+ m_CommodityShip.m_ShipStruct.m_Name+ "\"放入船坞");
        Player.Instance.m_ShipShopBuyIndices.Add(m_CommodityID);
        gameObject.SetActive(false);

        for(int i=0; i< m_CommodityShip.m_WeaponSlots.Count; ++i)
        {
            m_CommodityShip.m_WeaponSlots[i].equipPerloadWeapon();
        }
        Player.Instance.save();
    }
    protected override void showDescritionPanel()
    {
        base.showDescritionPanel();
        ShipDescriptionPanel panel = m_DescriptionPanel.GetComponent<ShipDescriptionPanel>();
        panel.Ship = m_CommodityShip as Ship;
    }
}
